package com.dingreading.cloud.soms.service.impl;

import com.dingreading.cloud.soms.entity.MemberFollowImg;
import com.dingreading.cloud.soms.entity.table.MemberFollowImgTableDef;
import com.dingreading.cloud.soms.mapper.MemberFollowImgMapper;
import com.dingreading.cloud.soms.service.MemberFollowImgService;
import com.mybatisflex.core.query.QueryCondition;
import com.mybatisflex.core.query.QueryWrapper;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 服务层实现。
 *
 * @author Administrator
 * @since 2024-09-24
 */
@Service
public class MemberFollowImgServiceImpl extends BaseServiceImpl<MemberFollowImgMapper, MemberFollowImg, MemberFollowImgTableDef> implements MemberFollowImgService {

    @Override
    protected MemberFollowImgTableDef getTable() {
        return MemberFollowImgTableDef.memberFollowImg;
    }

    @Override
    public int dropByFollowUid(String followUid) {
        return getMapper().deleteByCondition(table.followUid.eq(followUid));
    }

    @Override
    public int dropByFollowUidAndIdNot(String followUid, List<Long> ids) {
        QueryCondition condition = table.followUid.eq(followUid);
        if (CollectionUtils.isNotEmpty(ids))
            condition.and(table.id.notIn(ids));
        return getMapper().deleteByCondition(condition);
    }

    @Override
    public List<MemberFollowImg> listByFollowUidIn(List<String> uidList) {
        return getMapper().selectListByCondition(table.followUid.in(uidList));
    }

    @Override
    public List<MemberFollowImg> listByFollowUid(String followUid) {
        return getMapper().selectListByCondition(table.followUid.eq(followUid));
    }

    @Override
    public List<String> urlListByFollowUid(String followUid) {
        QueryWrapper wrapper = QueryWrapper.create()
                .select(table.imgUrl)
                .from(table)
                .where(table.followUid.eq(followUid));
        return getMapper().selectObjectListByQueryAs(wrapper, String.class);
    }

    @Override
    public List<String> urlListByFollowUidAndIdNot(String followUid, List<Long> ids) {
        QueryCondition condition = table.followUid.eq(followUid);
        if (CollectionUtils.isNotEmpty(ids))
            condition.and(table.id.notIn(ids));
        QueryWrapper wrapper = QueryWrapper.create()
                .select(table.imgUrl)
                .from(table)
                .where(condition);
        return getMapper().selectObjectListByQueryAs(wrapper, String.class);
    }

}
